package com.siyuan.blog.service.system.impl;/*
 *@program:ejiajia

 *@description:

 *@author:X-C

 *@create:2020-05-30 16:43:21
 **/

import com.siyuan.blog.dao.system.CusMapper;
import com.siyuan.blog.domain.system.Cus;
import com.siyuan.blog.service.system.CusService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CusServiceImpl implements CusService {
    @Resource
    private CusMapper cusMapper;

    @Override
    public int md5Password(Cus cus) {
        String password = cus.getPassword();
        String saltStr = cus.getCount();
        String hashAlgorithmName = "MD5";//加密方式
        ByteSource salt = ByteSource.Util.bytes(saltStr);//以账号作为盐值
        int hashIterations = 56;//
        SimpleHash hash = new SimpleHash(hashAlgorithmName, password, salt, hashIterations);
        cus.setPassword(hash.toString());
        return cusMapper.insert(cus);
    }

    @Override
    public Cus findCusByAccount(String username) {
        Cus ex = new Cus();
        ex.setCount(username);
        Cus cus = cusMapper.selectOne(ex);
        return cus;
    }
}
